package com.yida.gwj.expend.outside.service.impl;

import java.util.List;

import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.yida.common.core.utils.DateUtils;
import com.yida.common.security.utils.SecurityUtils;
import com.yida.gwj.expend.outside.domain.GwjMaintenanceFundsBusinessHouse;
import com.yida.gwj.expend.outside.domain.dto.AllocatedAmountListDTO;
import com.yida.gwj.expend.outside.domain.dto.OwnerCommentsDetailDTO;
import com.yida.gwj.expend.outside.domain.request.AllocatedAmountRequest;
import com.yida.gwj.expend.outside.domain.request.GwjInsertHouseRequest;
import com.yida.gwj.expend.outside.enums.FlagStatusEnum;
import com.yida.gwj.expend.outside.mapper.GwjMaintenanceFundsBusinessHouseMapper;
import com.yida.gwj.expend.outside.service.IGwjMaintenanceFundsBusinessHouseService;

import cn.hutool.core.util.ObjectUtil;

/**
 * 业务房屋信息Service业务层处理
 *
 * @author lgp
 * @date 2023-02-20
 */
@Service
public class GwjMaintenanceFundsBusinessHouseServiceImpl implements IGwjMaintenanceFundsBusinessHouseService {
    @Autowired
    private GwjMaintenanceFundsBusinessHouseMapper gwjMaintenanceFundsBusinessHouseMapper;

    /**
     * 查询业务房屋信息
     *
     * @param businessHouseId 业务房屋信息主键
     * @return 业务房屋信息
     */
    @Override
    public GwjMaintenanceFundsBusinessHouse selectGwjMaintenanceFundsBusinessHouseByBusinessHouseId(Long businessHouseId) {
        return gwjMaintenanceFundsBusinessHouseMapper.selectGwjMaintenanceFundsBusinessHouseByBusinessHouseId(businessHouseId);
    }

    /**
     * 查询业务房屋信息列表
     *
     * @param gwjMaintenanceFundsBusinessHouse 业务房屋信息
     * @return 业务房屋信息
     */
    @Override
    public List<GwjMaintenanceFundsBusinessHouse> selectGwjMaintenanceFundsBusinessHouseList(GwjMaintenanceFundsBusinessHouse gwjMaintenanceFundsBusinessHouse) {
        return gwjMaintenanceFundsBusinessHouseMapper.selectGwjMaintenanceFundsBusinessHouseList(gwjMaintenanceFundsBusinessHouse);
    }

    /**
     * 新增业务房屋信息
     *
     * @param gwjMaintenanceFundsBusinessHouse 业务房屋信息
     * @return 结果
     */
    @Override
    public GwjMaintenanceFundsBusinessHouse insertGwjMaintenanceFundsBusinessHouse(GwjMaintenanceFundsBusinessHouse gwjMaintenanceFundsBusinessHouse) {
        // 20230619 hmh start
        gwjMaintenanceFundsBusinessHouse.setCreateBy(SecurityUtils.getUsername());
        // end
        if (ObjectUtil.notEqual(gwjMaintenanceFundsBusinessHouseMapper.insertGwjMaintenanceFundsBusinessHouse(gwjMaintenanceFundsBusinessHouse), FlagStatusEnum.SUC.getCode())) {
            return null;
        }
        return gwjMaintenanceFundsBusinessHouse;
    }

    /**
     * 批量新增基础数据（房屋）
     *
     * @param houses 基础数据（房屋）
     * @return 结果
     */
    @Override
    public int insertGwjMaintenanceFundsBusinessHouseList(List<GwjInsertHouseRequest> houses) {
        return gwjMaintenanceFundsBusinessHouseMapper.insertGwjMaintenanceFundsBusinessHouseList(houses);
    }

    /**
     * 批量新增基础数据（房屋）
     *
     * @param maintenanceFundsBusinessHouse 基础数据（房屋）
     * @return 结果
     */
    @Override
    public int insertBatchGwjMaintenanceFundsBusinessHouse(List<GwjMaintenanceFundsBusinessHouse> maintenanceFundsBusinessHouse) {
        return gwjMaintenanceFundsBusinessHouseMapper.insertBatchGwjMaintenanceFundsBusinessHouse(maintenanceFundsBusinessHouse);
    }

    /**
     * 修改业务房屋信息
     *
     * @param gwjMaintenanceFundsBusinessHouse 业务房屋信息
     * @return 结果
     */
    @Override
    public int updateGwjMaintenanceFundsBusinessHouse(GwjMaintenanceFundsBusinessHouse gwjMaintenanceFundsBusinessHouse) {
        // 20230619 hmh start
        gwjMaintenanceFundsBusinessHouse.setUpdateBy(SecurityUtils.getUsername());
        // end
        gwjMaintenanceFundsBusinessHouse.setUpdateTime(DateUtils.getNowDate());
        return gwjMaintenanceFundsBusinessHouseMapper.updateGwjMaintenanceFundsBusinessHouse(gwjMaintenanceFundsBusinessHouse);
    }

    /**
     * 批量删除业务房屋信息
     *
     * @param businessHouseIds 需要删除的业务房屋信息主键
     * @return 结果
     */
    @Override
    public int deleteGwjMaintenanceFundsBusinessHouseByBusinessHouseIds(Long[] businessHouseIds) {
        return gwjMaintenanceFundsBusinessHouseMapper.deleteGwjMaintenanceFundsBusinessHouseByBusinessHouseIds(businessHouseIds);
    }

    /**
     * 删除业务房屋信息信息
     *
     * @param businessHouseId 业务房屋信息主键
     * @return 结果
     */
    @Override
    public int deleteGwjMaintenanceFundsBusinessHouseByBusinessHouseId(Long businessHouseId) {
        return gwjMaintenanceFundsBusinessHouseMapper.deleteGwjMaintenanceFundsBusinessHouseByBusinessHouseId(businessHouseId);
    }

    @Override
    public int deleteGwjMaintenanceFundsBusinessHouseByBusinessId(Long bizId) {
        return gwjMaintenanceFundsBusinessHouseMapper.deleteGwjMaintenanceFundsBusinessHouseByBusinessId(bizId);
    }

    @Override
    public GwjMaintenanceFundsBusinessHouse selectGwjMaintenanceFundsBusinessHouseByBusinessId(Long bizId) {
        return gwjMaintenanceFundsBusinessHouseMapper.selectGwjMaintenanceFundsBusinessHouseByBusinessId(bizId);
    }

    @Override
    public int updateBatchGwjMaintenanceFundsBusinessHouse(@Param("maintenanceFundsBusinessHouseList") List<GwjMaintenanceFundsBusinessHouse> maintenanceFundsBusinessHouseList) {
        return gwjMaintenanceFundsBusinessHouseMapper.updateBatchMaintenanceFundsBusinessHouse(maintenanceFundsBusinessHouseList);
    }

    @Override
    public List<AllocatedAmountListDTO> allocatedAmountList(AllocatedAmountRequest allocatedAmountRequest) {
        return gwjMaintenanceFundsBusinessHouseMapper.allocatedAmountList(allocatedAmountRequest);
    }

    /**
     * 查询未选中房屋列表
     *
     * @param allocatedAmountRequest 业务房屋信息
     * @return 业务房屋信息集合
     */
    @Override
    public List<GwjMaintenanceFundsBusinessHouse> selectCancelHouseList(AllocatedAmountRequest allocatedAmountRequest) {
        return gwjMaintenanceFundsBusinessHouseMapper.selectCancelHouseList(allocatedAmountRequest);
    }

    /**
     * 查询房屋用途列表
     *
     * @return {@link List}<{@link String}>
     */
    @Override
    public List<String> selectUseTypeList() {
        return gwjMaintenanceFundsBusinessHouseMapper.selectUseTypeList();
    }

    // ------------------------新增功能区 20230630 hmh start----------------------------------
    /* 
     * 根据业务ID和房屋标识码查询房屋数据
     */
    @Override
    public GwjMaintenanceFundsBusinessHouse selectGwjMaintenanceFundsBusinessHouseByBizIdAndHouseCode(Long bizId, String houseCode) {
        return gwjMaintenanceFundsBusinessHouseMapper.selectGwjMaintenanceFundsBusinessHouseByBizIdAndHouseCode(bizId, houseCode);
    }

    /**
     * 根据业务ID和房屋编号进行批量更新
     * 
     * @param list
     * @return
     */
    @Override
    public int updateBatchMaintenanceFundsBusinessHouseByBizIdAndHouseCode(List<GwjMaintenanceFundsBusinessHouse> list) {
        return gwjMaintenanceFundsBusinessHouseMapper.updateBatchMaintenanceFundsBusinessHouseByBizIdAndHouseCode(list);
    }
    // ------------------------end -----------------------------------------------------------

    /**
     * 查询业主征求意见房屋信息
     * 
     * @param bizId 业务主键
     * @return
     */
    @Override
    public List<OwnerCommentsDetailDTO> selectOwnerCommentsDetailList(Long bizId) {
        return gwjMaintenanceFundsBusinessHouseMapper.selectOwnerCommentsDetailList(bizId);
    }
}
